﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class user_showNote : Wozuji.Logic.PageLogin
{
    protected void Page_Load(object sender, EventArgs e)
    {


        String nid = "";
        try
        {
            nid = Request.QueryString["nid"].ToString();

        }
        catch (Exception ex)
        {
            nid = "";
        }
        if (!nid.Equals(""))
        {

            try
            {
                Wozuji.Model.UserPost_t up = new Wozuji.Model.UserPost_t();
                Wozuji.BLL.UserPost_t upbll = new Wozuji.BLL.UserPost_t();
                up = upbll.GetModel(Convert.ToInt32(nid));
                title.Text = Server.HtmlDecode(up.UserPost_Title);
                Page.Header.Title = Server.HtmlDecode(up.UserPost_Title);
                Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
                Wozuji.BLL.Member_t mbbll = new Wozuji.BLL.Member_t();
                mb = mbbll.GetModel(Convert.ToInt32(Session["userid"]));
                String notinfo = mb.Member_Name + "发表于：" +up.UserPost_Time.Value.ToUniversalTime() + "  " + up.UserPost_Hit.ToString() + "次阅读" + "  " + up.UserPost_Replay.ToString() + "次回复";
                noteInfoDetail.Text = Server.HtmlDecode(notinfo);
                context.Text = Server.HtmlDecode(up.UserPost_Content);
                //点击数据更新
                up.UserPost_Hit = up.UserPost_Hit + 1;
                upbll.Update(up);

                try
                {

                    //得到回复
                    DataSet ds = new DataSet();
                    ds = Wozuji.DBUtility.DbHelperSQL.Query("select member_id,member_face,member_name,replay_Content,convert(varchar,replay_time,21) as replay_time from userreplay_t a,member_t b where b.member_id= a.replay_Member  and replay_post=" + nid.ToString().Replace("'","''"));

                    PagedDataSource objPds = new PagedDataSource();

                    objPds.DataSource = ds.Tables[0].DefaultView;

                    objPds.AllowPaging = true;
                    objPds.PageSize = 5;
                    int CurPage;
                    if (Request.QueryString["Page"] != null)
                        CurPage = Convert.ToInt32(Request.QueryString["Page"]);
                    else
                        CurPage = 1;

                    objPds.CurrentPageIndex = CurPage - 1;
                    lblCurrentPage.Text = "当前页：" + CurPage.ToString();

                    if (!objPds.IsFirstPage)
                        lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);

                    if (!objPds.IsLastPage)
                        lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);



                    Repeater1.DataSource = objPds;
                    Repeater1.DataBind();
                }
                catch (Exception ex)
                {
                    privateValues.Text = "<<还没有人哦>>";
                }




            }
            catch (Exception ex)
            {

            }
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String nid = "";
        try
        {
            nid = Request.QueryString["nid"].ToString();

        }
        catch (Exception ex)
        {
            nid = "";
        }
        if (!nid.Equals(""))
        {
            try
            {

                if (TextBox1.Text.ToString().Length < 8)
                {
                    Wozuji.Common.MessageBox.Show(Page, "不得少于8个字符");
                }
                else
                {
                    Wozuji.Model.UserReplay_t Ur = new Wozuji.Model.UserReplay_t();
                    Ur.Replay_Member = Convert.ToInt32(Session["userid"].ToString());
                    Ur.Replay_Post = Convert.ToInt32(Request.QueryString["nid"].ToString());
                    Ur.Replay_Time = DateTime.Now;
                    Ur.Replay_Content = TextBox1.Text;
                    Wozuji.BLL.UserReplay_t urbll = new Wozuji.BLL.UserReplay_t();
                    urbll.Add(Ur);
                    //更新回复数量
                    Wozuji.Model.UserPost_t up = new Wozuji.Model.UserPost_t();
                    Wozuji.BLL.UserPost_t upbll = new Wozuji.BLL.UserPost_t();
                    up = upbll.GetModel(Convert.ToInt32(Request.QueryString["nid"].ToString().Replace("'","''")));
                    up.UserPost_Replay = up.UserPost_Replay + 1;
                    upbll.Update(up);
                    Wozuji.Common.MessageBox.Show(Page, "回复成功");

                }
            }
            catch (Exception ex)
            {
                Wozuji.Common.MessageBox.Show(Page, "回复不成功，稍后再试！");
            }
        }

    }
}
